package com.neu.emp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
	 * 
	 * @author neustu
	 *     通过jdbc完成对emp表的数据删除，删除empno为7777的员工信息；
	 */
public class Demo05 {
	private static String url = "jdbc:mysql://localhost:3306/mjq";
	private static String userName = "root";
	private static String pass = "mysql";
	private static String driver = "com.mysql.jdbc.Driver";
	public static Connection conn;
	public static PreparedStatement ps;
	static {
		try {
		//  驱动的加载   对应的方法是    Class.forName(driver);
			//  先生成下面的代码   然后快捷生成  try{}
			Class.forName(driver);
			//  生成    Connection 对象
			conn=DriverManager.getConnection(url,userName,pass);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	
	/**
	 * 
	 * @param args
	 *   删除   
	 */
	
	public static boolean delete(int b) throws SQLException {
		boolean flag = false;
		String sql ="delete from tb_emp where empno=?";
		ps= conn.prepareStatement(sql);
		ps.setInt(1,b);
		int a = ps.executeUpdate();
		if(a>0) {
			flag = true;
		}
		return flag;
	}
	public static void main(String[] args) throws SQLException {
		delete(7777);

	}

}
